package com.zhoujing.springsecurity.controller;

import com.zhoujing.springsecurity.dto.ResponseResult;
import com.zhoujing.springsecurity.pojo.SysUser;
import com.zhoujing.springsecurity.service.SysUserService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author 周敬
 * @version 1.0
 * @packageName com.zhoujing.springsecurity.controller
 * @fileName SysUserController
 * @createTime 2022/3/7-16:48-星期一
 * @lastModify 2022/3/7-16:48-星期一
 */
@RestController
@RequestMapping("/api")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/hello")
    @PreAuthorize("hasAuthority('system:list')")
    public String hello() {
        return "hello";
    }

    @PostMapping("/login")
    public ResponseResult login(@RequestBody SysUser user) {
        return sysUserService.login(user);
    }

    /**
     * 退出登录
     *
     * @return
     */
    @GetMapping("/logout")
    public ResponseResult logout() {
        return sysUserService.logout();
    }
}
